package com.ruoyi.system.flink;

public class InterruptWaitingDemo extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            try {
                // 模拟任务代码
                System.out.println("模拟任务代码");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // ... 清理操作
                System.out.println(isInterrupted());//false
                // 重设中断标志位为true
//                Thread.currentThread().interrupt();
            }
            System.out.println("i="+i+";"+isInterrupted());//true
        }
    }

    public static void main(String[] args) {
        InterruptWaitingDemo thread = new InterruptWaitingDemo();
        thread.start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        thread.interrupt();
    }
}

